Google form correct answers

All possible and correct answers in English and French.


In [ ]:
%run "../Static data/French localization.ipynb"

Localization


In [ ]:
processGForm = not ('gform' in globals())
if processGForm:
    gformFR.columns = gformEN.columns

getTranslatedForm tinkering


In [ ]:
#type(gformFR.index), type(gformEN.index)

In [ ]:
if processGForm:
    localizedForm = gformFR.copy()
    localizedPossibleAnswers = questionsAnswersTranslationsFR.copy()

    #def getTranslatedForm( localizedForm, localizedPossibleAnswers ):
    result = localizedForm.copy()
    result.index = pd.Series(result.index).apply(str)
    localizedPossibleAnswers.index = pd.Series(localizedPossibleAnswers.index).apply(str)

    # translate answers
    for question in result.columns:
        for index in result.index:
            answer = result.loc[index, question]
            if (
                0 != len(localizedPossibleAnswers.loc[question])
                and
                (answer in localizedPossibleAnswers.loc[question][0])
            ):  
                #print(result.loc[index, question])
                #print(localizedPossibleAnswers.loc[question][0][answer])
                result.loc[index, question] =\
                localizedPossibleAnswers.loc[question][0][answer]

    # translate questions
    result = result.rename(columns=dict(zip(localizedForm.columns,gformEN.columns)))

    #result

answer = gformFR.loc[index, question] answer


In [ ]:
if processGForm:
    # returns an English-indexed, English-localized answer dataframe
    #  from a French-indexed, French-localized dataframe
    def getTranslatedForm( _localizedForm, localizedPossibleAnswers ):
        result = localizedForm.copy()
        result.index = pd.Series(result.index).apply(str)
        localizedPossibleAnswers.index = pd.Series(localizedPossibleAnswers.index).apply(str)

        # translate answers
        for question in result.columns:
            for index in result.index:
                answer = result.loc[index, question]
                if (
                    0 != len(localizedPossibleAnswers.loc[question])
                    and
                    (answer in localizedPossibleAnswers.loc[question][0])
                ):  
                    #print(result.loc[index, question])
                    #print(localizedPossibleAnswers.loc[question][0][answer])
                    result.loc[index, question] =\
                    localizedPossibleAnswers.loc[question][0][answer]

        # translate questions
        result = result.rename(columns=dict(zip(localizedForm.columns,gformEN.columns)))

        return result

Merge


In [ ]:
if processGForm:
    gform = pd.concat([gformEN, getTranslatedForm( gformFR, questionsAnswersTranslationsFR )])
    gform.index = range(0, len(gform.index))